<template>
  <a-range-picker
    v-model="startEndMonth"
    :placeholder="['开始年', '结束年']"
    format="YYYY"
    :mode="mode2"
    @panelChange="handlePanelChange2"
    style="width: 100%"
  />
</template>

<script>
import { getAction } from '@/api/manage'
export default {
  name: 'BVariety',
  props: {
    value: [String, Number],
    showAll: {
      type: Boolean,
      default: false,
    },
    placeholder: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      mode2: ['year', 'year'],
      startEndMonthValue: [],
      startEndMonth: [],
    }
  },
  watch: {
    value(newVal) {
      if (!newVal) {
        this.startEndMonth = []
      }
    },
  },
  // created() {
  //   if (this.option.length == 0) this.getYearSelect()
  // },
  methods: {
    handlePanelChange2(value, mode) {
      this.startEndMonth = value
      this.$nextTick(() => {
        this.startEndMonthValue = [value[0].format('YYYY'), value[1].format('YYYY')]
        if(Number(this.startEndMonthValue[0])>Number(this.startEndMonthValue[1])){
           this.$message.warning('开始年份不能大于结束年份')
           return 
        }else{
          this.$emit('update:value', this.startEndMonthValue[0])
          this.$emit('update:value2', this.startEndMonthValue[1])
        }
      })
    },
  },
}
</script>
